<#escape x as x?html> <@h.commonHead title="角色管理" keywords="开源,永久免费"
description="springrain开源系统管理后台"/>
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<@h.naviHeader /> <@h.leftMenu />
		<!-- 主体内容开始 -->
		<div class="layui-body site-demo">

			<script type="text/javascript">
				var listurl = '${ctx}/system/role/list';

				var menuMultiSelectSetting = {
					expandAll : true,
					check : {
						enable : true,
						chkStyle : "checkbox",
						//chkboxType:  { "Y" : "", "N" : "" }
						chkboxType : {
							"Y" : "ps",
							"N" : "ps"
						}
					},
					data : {
						simpleData : {
							enable : true,
							idKey : "id",
							pIdKey : "pid",
							rootPId : "null"
						}
					}
				};

				jQuery(document).ready(
						function() {
							$(".widget-main tbody tr").click(
									function() {
										$(".sub_left_menu tbody tr.active")
												.removeClass("active");
										$(this).attr("class", "active");
										var _url = ctx
												+ "/system/role/look/json?id="
												+ $(this).attr("id");

										jQuery.ajax({
											url : _url,
											type : "post",
											dataType : "json",
											success : function(_json) {
												if (_json.status == "success") {
													showdata(_json);
												}
											}
										});
										return false;
									})
						});

				function showdata(result) {
					var fixed = result.data['fixed'];
					if (fixed == 1) {
						$("#btn_role_del").attr("onclick", "").hide();
					} else {
						$("#btn_role_del").attr("onclick", "deleteRole();")
								.show();
					}

					$("#btn_add").hide();
					$("#btn_update").show();
					$("#btn_reload").show();
					for ( var s in result.data) {
						set_val(s, result.data[s]);
					}

					var menuNames = "";
					var menuIds = "";

					jQuery(result.data.menus).each(function(i, obj) {
						menuNames = menuNames + obj.name + ",";
						menuIds = menuIds + obj.id + ",";
					});
					jQuery("#menuNames").val(menuNames);
					jQuery("#menuIds").val(menuIds);

				}

				function deleteRole() {
					var id = jQuery("#id").val();
					if (!id || id == "") {
						myalert("请选择你要删除的记录");
						return;
					} else {
						var _url = "${ctx}/system/role/delete?id=" + id;
						var listurl = "${ctx}/system/role/list";
						mydelete(_url, listurl);
					}
				}

				var menuMultiSelectTree;
				function showZtreeMenu() {

					if (!menuMultiSelectTree) {
						jQuery.post("${ctx}/system/menu/list/json", function(
								_json) {
							if (_json.status == "success") {
								$.fn.zTree.init($("#menuMultiSelectTree"),
										menuMultiSelectSetting, _json.data);
								menuMultiSelectTree = $.fn.zTree
										.getZTreeObj("menuMultiSelectTree");
								//zTree.expandAll(true);
								checkedZtreeNodes(jQuery("#menuIds").val(),
										"menuMultiSelectTree");
							} else {
								myalert(_json.message);
								return false;
							}
						});

					} else {
						checkedZtreeNodes(jQuery("#menuIds").val(),
								"menuMultiSelectTree");
					}

					//页面层-自定义
					layer.open({
						shadeClose : true,
						type : 1,
						title : "选择菜单",
						skin : 'layui-layer-rim', //加上边框
						area : [ '600px', '400px' ], //宽高
						content : $("#div_menuMultiSelectTree"),
						closeBtn : 1,
						btn : [ '确定' ], //按钮
						yes : function(index, layero) {
							selectZtreeMenu();
							layer.close(index); //如果设定了yes回调，需进行手工关闭
						}
					});

					return false;

				}

				function selectZtreeMenu() {

					var nodes = menuMultiSelectTree.getCheckedNodes(true);

					var menuNames = "";
					var menuIds = "";

					jQuery(nodes).each(function(i, obj) {
						menuNames = menuNames + obj.name + ",";
						menuIds = menuIds + obj.id + ",";
					});
					jQuery("#menuNames").val(menuNames);
					jQuery("#menuIds").val(menuIds);

				}

				function doupdate() {
					commonUpdateForm("updateForm", listurl, '角色更新成功！');
				}

				function dosave() {
					commonSaveForm("updateForm", listurl, '角色添加成功！');
				}
			//-->
			</script>
			<form class="form-horizontal" method="post"
				action="${ctx}/system/role/list" name="searchForm" id="searchForm">
				<input type="hidden" name="pageIndex" id="pageIndex"
					value="${(returnDatas.page.pageIndex)!'1'}" /> <input
					type="hidden" name="sort" id="page_sort"
					value="${(returnDatas.page.sort)!'desc'}" /> <input type="hidden"
					name="order" id="page_order"
					value="${(returnDatas.page.order)!'id'}" />
			</form>
			<div class="operate panel panel-default" style="height: 65px;">
				<div class="panel-body">
					<div class="pull-right">
						<@shiro.hasPermission name="/system/role/update" > <a
							id="btn_reload" href="javascript:location.reload();"
							class="btn  btn-sm  btn-primary" style="display: none;">
							跳转至新增 >> </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

						<a id="btn_add" href="javascript:dosave();"
							class="btn  btn-sm  btn-primary"> <img
							src="${ctx}/images/btn_save.png" />保存新增
						</a> <a id="btn_update" style="display: none;"
							href="javascript:doupdate();" class="btn  btn-sm  btn-primary">
							<img src="${ctx}/images/btn_save.png" />保存修改
						</a> </@shiro.hasPermission> <@shiro.hasPermission
						name="/system/role/delete" > <a onclick="" id="btn_role_del"
							class="btn btn-sm btn-danger" style="display: none;">删除</a>
						</@shiro.hasPermission>
					</div>
				</div>
			</div>
			<!-- 功能操作区域结束 -->
			<!-- 列表显示区域  -->
			<div class="row">
				<div class="col-sm-4">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">记录</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<table class="table table-striped table-bordered table-hover">
									<thead>
										<tr>
											<th>名称</th>
											<th>是否可用</th>
										</tr>
									</thead>
									<tbody>
										<#if (returnDatas.data??)&&(returnDatas.data?size>0)> <#list
										returnDatas.data as _data>
										<tr id="${(_data.id)!''}">
											<td>${(_data.name)!''}</td>
											<td>${(_data.state)!''}</td>
										</tr>
										</#list> </#if>
									</tbody>
								</table>
							</div>
						</div>
					</div>

				</div>
				<div class="col-sm-8 last">
					<div class="widget-box">
						<div class="widget-header">
							<h4 class="widget-title">内容</h4>
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<form id="updateForm" name="updateForm"
									action="${ctx}/system/role/update" method="post"
									class="form-horizontal clearfix">
									<input type="hidden" name="id" id="id">
									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="name">名称*：</label>
										<div class="col-sm-8">
											<input class="form-control" type="text" id="name" name="name"
												datatype="*" nullmsg="名称不能为空" />
										</div>
									</div>

									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="pid">权限菜单：</label>
										<div class="col-sm-8">
											<div class="input-group">
												<input name="menuNames" class="form-control val"
													id="menuNames" type="text" readonly="readonly" /> <input
													name="menuIds" id="menuIds" type="hidden" /> <span
													class="input-group-btn"> <a
													onclick="showZtreeMenu();" class="btn btn-sm btn-primary">
														<i class="fa fa-search"></i>
												</a>
												</span>
											</div>
										</div>
									</div>
									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="is_del">是否可用</label>
										<div class="col-sm-8">
											<select class="form-control" name="state" id="state">
												<option value="是">是</option>
												<option value="否">否</option>
											</select>
										</div>
									</div>
									<div class="form-group col-xs-9">
										<label class="col-sm-4 control-label" for="remark">备注：</label>
										<div class="col-sm-8">
											<textarea class="form-control" name="remark" id="remark"
												rows="5" class="col-xs-12"></textarea>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
				<div id="laypageDiv"></div>
				<@h.layPage cont="laypageDiv" formId="searchForm" page=returnDatas.page/>
			</div>
			<div id="div_menuMultiSelectTree">
				<ul id="menuMultiSelectTree" class="ztree"></ul>
			</div>

		</div>
		<!-- 主体内容结束 -->
		<@h.footer />
	</div>
</body>
</html>
</#escape>
